<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl">
    <script src="/js/plugins/chosen/chosen.jquery.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/chosen/chosen.min.css" type="text/css" />

</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <!--设置当前要回显当前菜单,必须在载人菜单前完成设置-->
            <#assign menu="strategyCatalog"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略分类管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyCatalog/list.do" method="post">
                <input type="hidden" id="currentPage" name="currentPage" value="1">
                <div class="form-group">
                    <label>攻略搜索:</label>
                    <select class="chosen-select form-control" name="strategyId" value="${(qo.strategyId)!}"
                            id="strategy" data-placeholder="请选择所属攻略">
                        <option value="-1">--请选择所属攻略--</option>
                        <#list strategies as s>
                            <option value="${s.id}">${s.title}</option>
                        </#list>
                    </select>
                </div>
                <script>
                    $("#strategy").val(${qo.strategyId!})
                </script>
                <button type="submit" class="btn btn-success">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <button type="button" class="btn btn-success updateBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加攻略分类
                </button>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>分类名称</th>
                    <th>所属攻略</th>
                    <th>排序</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                <#list result.list as entity>
                <tr>
                    <td>${entity.name!}</td>
                    <td>${(entity.strategy.title)!}</td>
                    <td>${(entity.sequence)!}</td>
                    <td>${(entity.stateName)!}</td>
                    <td><a href="javascript:;" class="updateBtn" data-json='${entity.jsonString}'>修改</a></td>
                </tr>
                </#list>
            </table>
           <#include "../common/page.ftl">
        </div>
    </div>
</div>

<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategyCatalog/saveOrUpdate.do" method="post" id="editForm"
                      enctype="multipart/form-data">
                    <input type="hidden" name="id"/>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">分类名称：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="name" placeholder="请输入分类名称"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">所属攻略：</label>
                        <div class="col-lg-6">
                            <select type="text" class="form-control" name="strategy.id">
                                <#list strategies as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">排序：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="sequence"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">状态：</label>
                        <div class="col-lg-6">
                            <select  class="form-control" name="state">
                                    <option value="true">启用</option>
                                    <option value="false">禁用</option>
                            </select>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary saveBtn">保存</button>
            </div>
        </div>
    </div>
</div>



<script>
    $(".updateBtn").click(function () {
        $("#editForm").clearForm(true);
        var json = $(this).data("json");
        if(json){
            $("#editForm input[name=id]").val(json.id);
            $("#editForm input[name=name]").val(json.name);
            $("#editForm select[name='strategy.id']").val(json.strategyId);
            $("#editForm input[name=sequence]").val(json.sequence);
            $("#editForm select[name=state]").val(json.state+"");
        }
        $("#inputModal").modal("show");
    });

    $(".saveBtn").click(function () {
        $("#editForm").ajaxSubmit(function (data) {
            console.log(data);
            if (data.success) {
                reload();
            } else {
                $.message.alert("提示", data.msg);
            }
        });
    });

    $('.chosen-select').chosen({
        no_results_text: "没有找到结果！",//搜索无结果时显示的提示
        search_contains:true,   //关键字模糊搜索。设置为true，只要选项包含搜索词就会显示；设置为false，则要求从选项开头开始匹配
        allow_single_deselect:true, //单选下拉框是否允许取消选择。如果允许，选中选项会有一个x号可以删除选项
        disable_search: false, //禁用搜索。设置为true，则无法搜索选项。
        disable_search_threshold: 0, //当选项少等于于指定个数时禁用搜索。
        inherit_select_classes: false, //是否继承原下拉框的样式类，此处设为继承
        width: '160px', //设置chosen下拉框的宽度。即使原下拉框本身设置了宽度，也会被width覆盖。
        max_shown_results: 1000, //下拉框最大显示选项数量
        display_disabled_options: false,
        single_backstroke_delete: false, //false表示按两次删除键才能删除选项，true表示按一次删除键即可删除
        case_sensitive_search: false, //搜索大小写敏感。此处设为不敏感
        group_search: false, //选项组是否可搜。此处搜索不可搜
        include_group_label_in_selected: true //选中选项是否显示选项分组。false不显示，true显示。默认false。
    });
</script>
</body>
</html>